#!/bin/sh

cd `dirname $0`

port=30080

echo $1
if [ "$1" = "stop" -o  "$1" = "restart"  ]
then
   echo `date` stop launch2  >>./launch2.log
   curl -X POST http://127.0.0.1:${port}/management/shutdown

  
   while [ $? -eq 0 ]
   do
     sleep 1
     echo shutdown...
     netstat -nltp | grep ":${port}" | grep -Po "\d+/.+$" | grep -Po "\d+" | xargs -r kill -2
     curl -X POST http://127.0.0.1:${port}/management/shutdown 
     
   done
fi
if [ "$1" != "stop" ]
then
    echo `date` start launch2  >>./launch2.log
    source /etc/profile

    if [ -z ${btcloud_home} ] 
    then
      export btcloud_home=`pwd`/../
    fi

    if [ -z ${JAVA_HOME} ]
    then
       export JAVA_HOME=`pwd`/../base/jre/
    fi

    java=${JAVA_HOME}/bin/java
    

    ${java} -Xms64m -Xmx128m -Dapplication.name=launch2 -jar ./launch2.jar
fi

